/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dvd.gestionnaires;

import java.util.Collection;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.management.Query;

/**
 *
 * @author cheikhndiaye
 */
@Stateless
@LocalBean
public class GestionnaireAdministrateur {
@PersistenceContext  

public void creerAdministrateurDeTest() {  
        creeAdministrateur("1","cheikh","cheikh", "Lennon", "jlennon");  
        creeAdministrateur("2","aby","aby", "Mac Cartney", "pmc");  
        creeAdministrateur("3","amy","amy", "Starr", "rstarr");  
        creeAdministrateur("4","mari", "mari", "Harisson", "georgesH");  
    }

public Administrateur creeAdministrateur(String Identifiant, String MotDePasse, String Nom, String Prenom, String Mail) {  
        Administrateur a = new Administrateur(Identifian, MotDePasse, Nom, Prenom, Mail);  
        em.persist(a);  
        return a;  
    }

 public Collection<Administrateur> getAllUsers() {  
        // Exécution d'une requête équivalente à un select *  
        Query q = em.createQuery("select u from Administrateur a");  
        return q.getResultList();  
    } 
            

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
  public void updateAdministrateur(String login, String pwd, String nom, String prenom){
       Query q =em.createQuery("update Administrateur q set q.motDePasse =:param2, q.Nom = :param3, q.prenom = :param4, q.mail = :param5 where q.Identifiant =:param1"); 
       q.setParameter("param1", Indentifiant);
       q.setParameter("param2", MotDePasse);
       q.setParameter("param3", Nom);
       q.setParameter("param4", Prenom);
       q.setParameter("param5", Mail);
       
       q.executeUpdate();    
   }
  
 public void supprimerAdministrateur(String Identifiant){
       Query q =em.createQuery("delete from Administrateur u where q.identifiant =:param");
       q.setParameter("param", indentifiant);
       q.executeUpdate();
               
   }
}
}
